# -*- coding: utf-8 -*-
"""
@Time ： 2021/4/19 22:12
@Auth ： Mr. royalday 2487625775
@Company ： 2487625775@qq.cpm
@Function ：请输入模块功能描述
"""
from django.conf.urls import include
from django.urls import path, re_path
from django.views.generic import RedirectView
from web.views import account, home, project, manage, wiki, file, setting, issues, api_view as api

from drf_yasg import openapi
from drf_yasg.views import get_schema_view

swagger_info = openapi.Info(
    title="测试工程API",
    default_version='v1.0',
    description="测试工程接口文档",
    terms_of_service="https://www.google.com/policies/terms/",
    contact=openapi.Contact(email="2487625775@qq.com"),
    license=openapi.License(name="BSD License"),
)

SchemaView = get_schema_view(
    validators=['ssv', 'flex'],
    public=True,
)

# apirul
api_path = [
    path('swagger/', SchemaView.with_ui('swagger', cache_timeout=0), name='schema-swagger-ui'),
    path('redoc/', SchemaView.with_ui('redoc', cache_timeout=0), name='schema-redoc'),

    path('api/gettags/', api.gettags),
    path('api/case/getcase/', api.GetCase.as_view()),
    path('api/user/Login/', api.Login.as_view()),
    path('api/user/GetImgCode/', api.GetImgCode.as_view()),
]

# urlpatterns required for settings values
urlpatterns = [
    re_path(r'mdeditor/', include('mdeditor.urls')),
    # url('', home.index, name='index'),    # 首页
    # 登录注册
    re_path('$favicon.ico$', RedirectView.as_view(url=r'static/img/favicon.ico')),  # 标签页的logo
    path('favicon.ico/', RedirectView.as_view(url=r'static/img/favicon.ico')),  # 标签页的logo
    re_path(r'^$', account.redirect_index),  # url默认进入index页面

    path('register/', account.register, name='register'),  # 注册页面
    path('login/sms/', account.login_sms, name='login_sms'),  # 短信登录页面
    path('login/', account.login, name='login'),  # 短信登录页面
    path('img/code/', account.img_code, name='img_code'),  # 获取图片验证码
    path('send_sms/', account.send_sms, name='send_sms'),  # 发送短信验证码
    path('index/', home.index, name='index'),  # 首页

    path('update_password/', account.update_password, name='update_password'),  # 修改密码
    path('personal_center/', account.personal_center, name='personal_center'),  # 个人中心
    path('logout/', account.logout, name='logout'),  # 退出登录
    # 项目管理
    path('project/list/', project.project_list, name='project_list'),  # 项目列表

    # project/star/my/id
    # project/star/join/id
    re_path(r'project/star/(?P<project_type>\w+)/(?P<project_id>\d+)/',
            project.project_star, name='project_star'),  # 项目添加星标
    re_path(r'project/remove_star/(?P<project_type>\w+)/(?P<project_id>\d+)/',
            project.project_remove_star, name='project_remove_star'),  # 项目移除星标

    # 项目主页url
    re_path(r'manage/(?P<project_id>\d+)/', include([
        path('dashboard/', manage.dashboard, name='dashboard'),
        path('statistics/', manage.statistics, name='statistics'),

        # 项目的wiki管理
        path('wiki/', wiki.wiki, name='wiki'),
        path('wiki/add/', wiki.wiki_add, name='wiki_add'),
        path('wiki/wiki_catalog/', wiki.wiki_catalog, name='wiki_catalog'),
        path('wiki/wiki_detail/', wiki.wiki_detail, name='wiki_detail'),
        re_path(r'wiki/wiki_delete/(?P<wiki_id>\d+)/', wiki.wiki_delete, name='wiki_delete'),
        re_path(r'wiki/wiki_edit/(?P<wiki_id>\d+)/', wiki.wiki_edit, name='wiki_edit'),
        re_path(r'wiki/wiki_upload/', wiki.wiki_upload, name='wiki_upload'),

        # 项目的文件管理
        path('file/', file.file, name='file'),
        re_path(r'file/file_delete/', file.file_delete, name='file_delete'),
        re_path(r'cos/credential/', file.cos_credential, name='cos_credential'),
        re_path(r'file/save_database/', file.save_database, name='save_database'),
        re_path(r'file/download_file/(?P<file_id>\d+)/', file.download_file, name='download_file'),

        # 项目的设置
        path('setting/', setting.setting, name='setting'),
        path('setting/delete_project', setting.delete_project, name='delete_project'),

        path('issues/', issues.issues, name='issues'),
    ])),

] + api_path
